function useTheme(mode) {
  if (['dark', 'light'].includes(mode)) {
    let href = new URL(`./variable.${mode}.css`, import.meta.url).href;
    let link = document.querySelector('[data-type="theme-variable"]');
    if (!link) {
      link = document.createElement('link');
      link.setAttribute('rel', 'stylesheet');
      link.setAttribute('data-type', 'theme-variable');
      document.head.appendChild(link);
    }
    link.setAttribute('data-theme', mode);
    link.setAttribute('href', href);
    document.documentElement.setAttribute('data-theme', mode);
    document.documentElement.setAttribute('data-vxe-ui-theme', mode);
  }
}

export default useTheme;
